package xin.yangshuai.juc01.countdownlatch;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * Hello
 *
 * @author shuai
 * @date 2025/1/9
 */
public class Hello {

    public static void main(String[] args) {

        CountDownLatch countDownLatch = new CountDownLatch(10);

        AtomicInteger atomicInteger = new AtomicInteger(10);

        for (int i = 0; i < 10; i++) {
            new Thread(new Runnable() {

                @Override
                public void run() {
                    try {
                        Thread.sleep(10000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("------------------------"+atomicInteger.getAndDecrement());
                    countDownLatch.countDown();
                }
            }).start();
        }

        try {
            System.out.println("--------------等待异步执行完成");
            countDownLatch.await();
            System.out.println("--------------异步执行已完成");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("hello world");
    }
}
